package com.example.linearlayoutdemo.network.fun.viewmodel;

/**
 * 网络请求资源封装（含状态 + 数据 + 错误信息）
 */
public class Resource<T> {
    // 状态枚举
    public enum Status { LOADING, SUCCESS, ERROR }

    private final Status status;
    private final T data;
    private final String message;

    // 私有构造：通过静态方法创建实例
    private Resource(Status status, T data, String message) {
        this.status = status;
        this.data = data;
        this.message = message;
    }

    // 1. 加载中状态
    public static <T> Resource<T> loading(T data) {
        return new Resource<>(Status.LOADING, data, null);
    }

    // 2. 成功状态
    public static <T> Resource<T> success(T data) {
        return new Resource<>(Status.SUCCESS, data, null);
    }

    // 3. 失败状态
    public static <T> Resource<T> error(String message, T data) {
        return new Resource<>(Status.ERROR, data, message);
    }

    // Getter
    public Status getStatus() { return status; }
    public T getData() { return data; }
    public String getMessage() { return message; }
}
